package dfbz.com.service.impl;

import dfbz.com.dao.StudentDao;
import dfbz.com.model.Student;
import dfbz.com.pojo.Person;
import dfbz.com.service.StudentService;

import java.util.List;

public class StudentServiceImpl implements StudentService {

    private StudentDao studentDao = new StudentDao();


    @Override
    public List<Student> findAll() {
        return studentDao.findAll(Student.class);
    }

    @Override
    public void add(Person person) {
        Student student = new Student();
        student.setId(person.getNum());
        student.setName(person.getName());
        student.setPhone(person.getTel());
        student.setAddress(person.getAddr());
        studentDao.add(student);
    }

    @Override
    public void delById(String id) {
        studentDao.del(id, Student.class);
    }

    @Override
    public Student findById(String id) {
        return studentDao.get(id, Student.class);
    }

    @Override
    public void update(Person person) {
        if (null != person.getNum()) {
            Student student = new Student();
            student.setId(person.getNum());
            student.setName(person.getName());
            student.setPhone(person.getTel());
            student.setAddress(person.getAddr());
            studentDao.update(student);
        }
    }


}
